package com.yin.jia.liang.service;

import com.yin.jia.liang.dao.GoodsOrderMapper;
import com.yin.jia.liang.entity.GoodsOrder;
import com.yin.jia.liang.entity.GoodsOrderExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    GoodsOrderMapper orderMapper;

    public GoodsOrder findById(Integer id) {
        return orderMapper.selectByPrimaryKey(id);
    }

    public List<GoodsOrder> findByUserId(int userId) {
        GoodsOrderExample ue = new GoodsOrderExample();
        GoodsOrderExample.Criteria criteria = ue.createCriteria();
        criteria.andUserIdEqualTo(userId);
        ue.setOrderByClause("id desc");
        List<GoodsOrder> g = orderMapper.selectByExample(ue);

        return g;
    }

    public List<GoodsOrder> find() {
        GoodsOrderExample ue = new GoodsOrderExample();
        ue.setOrderByClause("id desc");
        List<GoodsOrder> g = orderMapper.selectByExample(ue);

        return g;
    }

    public Integer save(GoodsOrder order) {
        int i = orderMapper.insert(order);
        return i;
    }

    public int update(GoodsOrder order) {
        int i = orderMapper.updateByPrimaryKeySelective(order);
        return i;
    }

    public Integer delete(Integer id) {
        return orderMapper.deleteByPrimaryKey(id);
    }
}
